package com.cssw.fyzb.busi.api.live;

import com.cssw.fyzb.core.model.vo.live.LiveGiftCountVo;
import com.cssw.fyzb.busi.service.live.GiftService;
import com.cssw.fyzb.busi.service.live.LiveService;
import com.cssw.fyzb.core.model.dodb.CmfGift;
import com.cssw.fyzb.core.model.mos.GiftNumMo;
import com.cssw.fyzb.core.model.mos.UserLiveMo;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 查询主播直播获取的礼物信息
 *
 * @author YangYiQun
 */
@Function(description = "查询主播直播获取的礼物信息", parameters = {
        @Parameter(name = "liveId", type = Type.String, description = "直播标识", required = true),
        @Parameter(name = "userId", type = Type.String, description = "用户标识", required = true)
})
@Component
public class ListLiveGiftCount implements Action {

    private static final Logger logger = LoggerFactory.getLogger(ListLiveGiftCount.class);

    @Autowired
    LiveService liveService;

    @Autowired
    GiftService giftService;

    @Override
    public Response execute(Request request) throws Exception {
        Long userId = request.getLong("userId");
        Long liveId = request.getLong("liveId");
        try {
            UserLiveMo userLive = liveService.getUserLive(liveId);
            List<LiveGiftCountVo> vos = new ArrayList<>();
            List<GiftNumMo> gifts = userLive.getGifts();

            if (null != gifts && gifts.size() > 0) {
                LiveGiftCountVo vo = null;
                for (GiftNumMo giftNumMo : gifts) {
                    vo = new LiveGiftCountVo();
                    vo.setGiftId(giftNumMo.getGiftId());
                    CmfGift cmfGift = giftService.queryById(giftNumMo.getGiftId());

//                    vo.setGiftName(cmfGift.getGiftName());
//                    vo.setIconMini(cmfGift.getIconMini());
//                    vo.setImage(cmfGift.getImage());

                    vo.setNum(giftNumMo.getNum());
                    vos.add(vo);
                }
            }

            return Response.success().put("list", vos);
        } catch (Exception e){
            logger.error("", e);
            return Response.fail("操作失败");
        }
    }
}
